import { $C, $rp } from '@/utils/constants';

const noteP = $C.notifications.position;

export default (note) => {
  const errs = ['点赞提醒参数错误'];
  if (note.authorInfo.err) errs.push(note.authorInfo.msg);
  if (note.spaceInfo.err) errs.push(note.spaceInfo.msg);
  if (note.noteInfo.err) errs.push(note.noteInfo.msg);

  if (errs.length > 1) return { id: note.id, err: true, msg: errs.join(', ') };

  let [desc, rootPath, notePath] = [];
  const spacePath = `/${$rp.SPACES}/${note.spaceInfo.id}`;
  // 评论点赞和其它位置的点赞，路由生成参数位置不一样，noteInfo中的参数只针对note本身
  // const docPath = note.noteInfo.position === noteP.comment
  // eslint-disable-next-line max-len
  //   ? Base64.encodeURI(`${note.voteInfo.positionParentPath || ''}/${note.voteInfo.positionId}-${note.voteInfo.positionTitle}`) // 点赞专用path
  // eslint-disable-next-line max-len
  //   : Base64.encodeURI(`${note.noteInfo.parentPath || ''}/${note.noteInfo.id}-${note.noteInfo.title}`); // 资源点赞专用path

  switch (note.noteInfo.position) {
    case noteP.space:
      desc = '点赞了我的空间';
      rootPath = spacePath;
      break;
    case noteP.doc:
      desc = '点赞了我的资源';
      rootPath = `${spacePath}/resources-docs/${note.noteInfo.id}`;
      break;
    case noteP.issue:
      desc = '点赞了我的问题';
      rootPath = `${spacePath}/${$rp.SPACE_ISSUES}/${note.noteInfo.id}`;
      break;
    case noteP.ctrb:
      desc = '点赞了我的贡献';
      rootPath = `${spacePath}/${$rp.SPACE_CONTRIBUTIONS}/${note.noteInfo.id}`;
      break;
    case noteP.comment:
      desc = '点赞了我的评论';
      switch (note.voteInfo.position) {
        case noteP.doc: // 点赞了资源下的评论
          rootPath = `${spacePath}/resources-docs/${note.voteInfo.positionId}`;
          break;
        case noteP.issue: // 点赞了问题下的评论
          rootPath = `${spacePath}/${$rp.SPACE_ISSUES}/${note.voteInfo.positionId}`;
          break;
        case noteP.ctrb: // 点赞了贡献下的评论
          rootPath = `${spacePath}/${$rp.SPACE_CONTRIBUTIONS}/${note.voteInfo.positionId}`;
          break;
        default: errs.push('错误的评论位置votePosition');
      }
      break;
    default: errs.push('错误的消息位置position');
  }

  // 楼层参数
  if (note.noteInfo.position === noteP.comment) { // 当对评论点赞时，生成具体位置
    if (!note.noteInfo.parentId) { // 当不是对楼中楼点赞时
      const mainFloorPage = parseInt(note.noteInfo.floor / 10, 10) + 1; // 主楼在第几页
      notePath = `${rootPath}?page=${mainFloorPage}&comment_id=${note.noteInfo.id}`;
    } else {
      const mainFloorPage = parseInt(note.noteInfo.parentFloor / 10, 10) + 1; // 主页在第几楼
      const subFloorPage = parseInt(note.noteInfo.floor / 10, 10) + 1; // 楼中楼在第几楼
      notePath = `${rootPath}?page=${mainFloorPage}&comment_id=${note.noteInfo.parentId}&sub_page=${subFloorPage}&sub_comment_id=${note.noteInfo.id}`;
    }
  }

  return {
    type: note.type,
    author: note.authorInfo,
    desc,
    root: { title: note.noteInfo.title, content: note.noteInfo.content, path: rootPath },
    notePath,

    id: note.id,
    read: note.read,
    created_at: note.created_at,
    updated_at: note.updated_at,
  };
};
